<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:context="http://www.springframework.org/schema/context"
       xmlns:mvc="http://www.springframework.org/schema/mvc" 
       xsi:schemaLocation="
        http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
        http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
        http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd">
  <!--
    Copyright 2017 Open Source Geospatial Foundation. All rights reserved.
    This code is licensed under the GPL 2.0 license, available at the root application
    directory.
  -->
  
	<context:component-scan base-package="org.geoserver.geofence.server.rest"/>
          
    <!-- ================================================================ -->
    <!-- =============== Property override ============================== -->
    <!-- ================================================================ -->
    <bean id="geofence-server-configurer" class="org.geoserver.geofence.config.GeoFencePropertyPlaceholderConfigurer">

        <property name="order" value="99"/>
        
        <constructor-arg ref="dataDirectory"/>

        <property name="ignoreResourceNotFound" value="true" />
        <property name="ignoreUnresolvablePlaceholders" value="true" />

        <!-- This location is relative to the datadir -->
        <property name="location" value="file:geofence/geofence-server.properties"/>

        <!-- default properties -->
        <property name="properties">
            <props>
            	<prop key="geofence-ovr">geofence-datasource-ovr.properties</prop>

                <!-- The backend will be injected in the cached reader. -->
                <!-- use the server rule reader service directly -->
                <prop key="ruleReaderBackend">ruleReaderService</prop>

                <!-- The frontend will be injected in the access manager. -->
                <!-- You may replace the cachedRuleReader ref with ruleReaderService in order to disable the caching -->
                <!--<prop key="ruleReaderFrontend">ruleReaderService</prop>-->
                <prop key="ruleReaderFrontend">cachedRuleReader</prop>
            </props>
        </property>
    </bean>

    <alias name="geofence-server-configurer" alias="geofence-configurer"/>
       
    <bean class="org.geoserver.config.GeoServerPropertyOverrideConfigurer" >
        <constructor-arg ref="dataDirectory"/>
        <property name="ignoreResourceNotFound" value="true"/>
        <property name="locations">
            <list>
                <!-- Default values for an embedded file-based H2 db -->
                <value>classpath*:geofence-default-override.properties</value>
                <!-- Optional overriding values for custom db. Path relative to data dir -->
                <value>file:geofence/geofence-datasource-ovr.properties</value>
                <!-- Optional, use this property if you want to keep your ovr file in a different location than the data dir -->
                <value>${geofence-ovr}</value>
            </list>
        </property>
        <property name="properties">
            <props>
                <!-- This value is used to find out if we are using an embedded geofence instance -->
                <prop key="geofenceConfigurationManager.configuration.servicesUrl">internal:/</prop>
                <!--  db inside data directory -->
                <prop key="geofenceDataSource.url">jdbc:h2:${GEOSERVER_DATA_DIR}/geofence/geofence_db/geofence</prop>
                <!-- "update" is not a good option in production -->
                <prop key="geofenceEntityManagerFactory.jpaPropertyMap[hibernate.hbm2ddl.auto]">update</prop>
            </props>
        </property>
    </bean>

    <!-- use the internal user resolver so geofence uses geoserver users and roles rather than its own -->
    <bean id="securityContextUserResolver" class="org.geoserver.geofence.server.internal.SecurityContextUserResolver" />

    <alias name="securityContextUserResolver" alias="defaultUserResolver" />
    
    <!-- web admin page -->
    <bean id="geofenceServerPage" class="org.geoserver.web.MenuPageInfo">
       <property name="id" value="geofenceServerPage"/>
       <property name="titleKey" value="GeofenceServerPage.page.title"/>
       <property name="descriptionKey" value="GeofenceServerPage.page.description"/>
       <property name="componentClass" value="org.geoserver.geofence.server.web.GeofenceServerPage"/>
       <property name="category" ref="securityCategory" />
       <property name="order" value="1001" />
       <property name="icon" value="img/icons/geofence.png" />
    </bean>

    <bean id="geofenceServerAdminPage" class="org.geoserver.web.MenuPageInfo">
        <property name="id" value="geofenceServerAdminPage"/>
        <property name="titleKey" value="GeofenceServerAdminPage.page.title"/>
        <property name="descriptionKey" value="GeofenceServerAdminPage.page.description"/>
        <property name="componentClass" value="org.geoserver.geofence.server.web.GeofenceServerAdminPage"/>
        <property name="category" ref="securityCategory" />
        <property name="order" value="1002" />
        <property name="icon" value="img/icons/geofence.png" />
    </bean>
    
    <bean id="geofenceServerXStreamInitializer" 
          class="org.geoserver.geofence.server.xstream.GeoFenceServerXStreamInitializer"
          lazy-init="false">
    </bean>    

    <mvc:interceptors>
       <bean class="org.geoserver.geofence.server.rest.GeofenceSecurityInterceptor"/>
    </mvc:interceptors>
 
</beans>
